<?php echo $header; ?>

<!-- Content -->
<div id="main" class="p10t">
    <!-- Left column -->
    <?php echo $column_left; //$column_left_search; ?>

    <div id="col2" class="w709">
			<div class="box_tt">
				<h4 class="float_left p5t">Søg<span style="text-transform:none;"><?php echo !empty($products) ? ' - ' . $text_search : '' ?></span></h4>
				<!-- span class="float_right"><a href="<?php echo $back; ?>"><img src="catalog/view/theme/<?php echo $template; ?>/images/bt_tibage.png"/></a></span -->
			</div>
			<div class="box_content_underpage">
				<div class="box_content_underpage1 min_heght">   
				  	<div class="p15t p20l p20r">   
				  		<!-- Sort -->
                        <?php if(!empty($products) || true){ ?>
                            <div class="tt_top_pro1">
                                <!--
					            <?php echo $entry_search; ?>
					            <?php if ($keyword) { ?>
					                <input type="text" value="<?php echo $keyword; ?>" id="keyword" />
					            <?php } else { ?>
					                <input type="text" value="<?php echo $text_keyword; ?>" id="keyword" onclick="this.value = '';" onkeydown="this.style.color = '000000'" style="color: #999;" />
					            <?php } ?>
					            &nbsp;&nbsp;
					            -->    
                                
                                <div class="float_left" style="margin: 7px;">                                                                       
                                    <?php echo $text_sort; ?>
					        	    <select name="sort" onchange="location = this.value">
					          		    <?php foreach ($sorts as $sorts) { ?>
					          			    <?php if (($sort . '-' . $order) == $sorts['value']) { ?>
					          				    <option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option>
					          			    <?php } else { ?>
					          				    <option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option>
					          			    <?php } ?>
					          		    <?php } ?>
					        	    </select>
                                </div>    
                                <?php if (1==0){ ?> 
                                <div id="size_filter" class="page_top" style="margin: 7px;">                                                                          
                                    <?php echo $text_size; ?> 
                                    <select id="size_filter_item" name="size">
                                        <?php foreach ($sizes as $size) { ?>                                             
                                            <?php if($size['attribute_id'] == 0 || $size['items']){ ?>   
                                                <?php $rel = $size['attribute_id'] == 0 ? 'rel="' . $size['href'] . '"' : 'rel=""'; ?>  
                                                <?php $enable = $size['attribute_id'] == 0 ? '' : 'disabled="disabled"'; ?>                                           
                                                <option value="<?php echo $size['attribute_id']; ?>" <?php echo $rel . ' ' . $enable; ?>><?php echo $size['name']; ?></option>
                                                <?php foreach($size['items'] as $size_item){ ?>
                                                    <?php $selected = in_array($size_item['value_id'], $selected_size) ? 'selected="selected"' : ''; ?>
                                                    <option value="<?php echo $size_item['value_id']; ?>" rel="<?php echo $size['href']; ?>" <?php echo $selected; ?>>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $size_item['name']; ?></option>                                                    
                                                <?php } ?>                                                  
                                            <?php } ?>
                                        <?php } ?>
                                    </select>   
                                    
                                    <!--                         
                                    <div id="size_dialog">
                                        <div class="size_area">
                                            <?php foreach($sizes as $size){ ?>                                                                                         
                                                <?php if($size['attribute_id'] > 0 && $size['items']){ ?>
                                                    <div class="size_attribute">
                                                        <?php echo $size['name']; ?>
                                                        <ul>
                                                            <?php foreach($size['items'] as $size_item){ ?>
                                                                <li><?php echo $size_item['name']; ?></li>    
                                                            <?php } ?>
                                                        </ul>
                                                     </div>
                                                <?php } ?>
                                            <?php } ?>
                                        </div>
                                    </div>
                                    -->
                                </div>
                                <?php } ?> 
                                <div class="cb"></div>  
                            </div>                        
                        <?php } ?>
                        
                        <!-- Product details -->
                        <div class="products_list">                            
                            <?php if(!empty($products)){ ?>          
                                <?php $size = sizeof($products); ?>
                                <?php for ($i = 0; $i < $size; $i += 3) { //for ($i = 0; $i < $size; $i += 4) { ?> 
                                    <?php $count = 1 ; ?> 
                                    <?php for ($j = $i; $j < ($i + 3); $j++) { //for ($j = $i; $j < ($i + 4); $j++) { ?>
                                        <?php 
                                        if($size == $j){
                                            break;
                                        }
                                        
                                        //if($count % 4 == 0){ 
                                        if($count % 3 == 0){ 
                                            //$css_class = ' p26l p26t';
                                            $css_class = ' pr_pad_left p20t';
                                        }
                                        else{ 
                                            //$css_class = ' line_pro_right p28r' . (($count % 4 == 1) ? ' p20t' : ' pr_pad_left p20t'); 
                                            $css_class = ' line_pro_right pr_pad_right' . (($count % 3 == 1) ? ' p20t' : ' pr_pad_left p20t'); 
                                        }
                                        $count++;
                                        
                                        $item = $products[$j];  
                                        ?> 
                                        
                                        <div class="box_img_pro float_left<?php echo $css_class; ?> hover">
											<div class="product_img_container">
												<a href="<?php echo $item['href']; ?>" title="<?php echo $item['name']; ?>">
													<img src="<?php echo $item['thumb']; ?>" alt="<?php echo $item['name']; ?>" />
												</a>
												<?php if($item['options']) { ?>
													<a class="product_sizes_popup" href="<?php echo $item['href']; ?>">
														<?php $op = 0; ?>
														<?php foreach($item['options'] as $options){ ?>
															<?php                                            
															$option_data = '';                                            
															foreach($options['option_value'] as $option_item){
																$option_data .=  $option_item['name'] . ', ';
															}
															$option_data = trim($option_data, ', ');
															?>
																
															<p class="header <?php echo ($op > 0 ? ' p5t' : ''); ?>"><?php echo (strcasecmp($options['name'], 'Størrelse') == 0) ? 'Størrelser' : $options['name'] ?></p>
															<p class="data"><?php echo $option_data ?></p>
															<?php $op++; ?>
														<?php } ?>
													</a>
												<?php } ?>
											</div>
                                            <div id="test"></div>
                                            <div class="text_pro cat_product_name">
                                                <?php if(1==0){ ?>
                                                <?php echo $item['shortname']; ?><br>
                                                <span class="style1">ID: <?php echo $item['sku']; ?></span><br>
                                                <?php } ?>
                                                
                                                <?php echo $item['shortname']; ?>
                                                <?php //if($item['unbreak']){ echo '<br />';} ?>
                                                <div class="cat_price">
                                                    <?php if($item['discount']){ ?>
                                                        <span class="cat_style9"><span class="cat_style9_discount">&nbsp;<?php echo $item['ref_price'] ? 'Priser fra ' . $item['ref_price'] : $item['discount']; ?></span></span>&nbsp;&nbsp;
                                                        <span class="cat_style3"><span class="cat_style2_discount">&nbsp;<?php echo $item['price']; ?></span></span>
                                                    <?php }else{ ?>
                                                        <span class="cat_style2"><?php echo $item['ref_price'] ? 'Priser fra ' . $item['ref_price'] : $item['price']; ?></span><br>
                                                    <?php } ?> 
                                                </div>
                                                <!-- p><a href="<?php echo $item['href']; ?>" class="bg_buynow">Bestil nu</a></p -->
                                            </div>
                                        </div>                                       
                                    <?php } ?>
                                    
                                    <div class="cb"></div> 
                                <?php } ?>                                                                     
                            <?php }else { ?>    
                                <div><h3 style="text-align:center; text-transform:none; font-weight:bold; font-size:14px; color:#000; margin-top:20px;"><?php echo $text_empty; ?></h3></div>                             
                                <div class="cb"></div>
                            <?php } ?>                           
                        </div>
                        
                        <!-- Paging -->
                        <?php if(isset($pagination)){ ?>
                            <div class="tt_top_pro1 m12t">
                                   <?php echo $pagination; ?>
                            </div>
                        <?php } ?>
                    </div>
				</div>
			</div>
			
            <div class="box_bottom">
                <div class="all_page_bt"></div>
            </div>
        </div>
        
		<p class="cb"></p>
	</div>
</div>
<!-- End content -->

<!-- Footer -->
<?php echo $footer; ?> 

<link type="text/css" href="catalog/view/theme/<?php echo $template; ?>/css/jquery/smoothness/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript" src="catalog/view/theme/<?php echo $template; ?>/js/jquery.ui.core.js"></script>
<script type="text/javascript" src="catalog/view/theme/<?php echo $template; ?>/js/jquery.ui.position.js"></script>
<script type="text/javascript" src="catalog/view/theme/<?php echo $template; ?>/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="catalog/view/theme/<?php echo $template; ?>/js/jquery.ui.dialog.js"></script>
<script type="text/javascript"><!--  
    function addSizeFilter(){ 
        $('#size_dialog').dialog({
            autoOpen: false,
            modal: true,
            title: 'Vælg størrelse',
            resizable: false,
            width: 600,
            height: 400
        });        
    }
    
    jQuery(document).ready(function(){
        //addSizeFilter();        
        $('#size_filter_item').change(function(){ 
            var href = $('option:selected', this).attr('rel');
            var val = $('option:selected', this).attr('value');
            if(href != '' && val > 0){
                window.location = href + val;
            }
            else if(val == 0){
                window.location = href;    
            }   
        });
		
		jQuery(".product_img_container").mouseover(
            function(event){
				var element =  jQuery(this).children('.product_sizes_popup');
				if(element.length > 0){
					element.css({display: "block"});
				}
            }).mouseout(function(event){
				var element =  jQuery(this).children('.product_sizes_popup');
                if(element.length > 0){
					element.css({display: "none"});
				}
            }
        );
    });
    
    /*
    $('#open_filter').click(function(e) {
        //$('#size_dialog').dialog('destroy');
        //addSizeFilter();
        $('#size_dialog').dialog('open');    
    });
    */
	/*
	$('#keyword').keydown(function(e) {
		if (e.keyCode == 13) {
			contentSearch();
		}
	});
    */
    /*
    jQuery(document).ready(function(){ 
        var color = jQuery('.hover').css('background-color');
                 
        jQuery('.hover').hover(
            function(){                                
                jQuery(this).css('background-color', '#C0C0C0');
            },
            function(){ 
                jQuery(this).css('background-color', color);                    
            }
        ); 
    });
    */
	function contentSearch() {
		url = 'index.php?route=product/search';
		
		var keyword = $('#keyword').attr('value');    		
		if (keyword) {
			url += '&keyword=' + encodeURIComponent(keyword);
		}              

		location = url;
	}
//-->
</script>